package com.google.code.jtasks.bugzilla.fields;

/**
 * Enumerates the standard Bugzilla fields.
 */
public enum BugzillaStandardField
{
	PRIORITY("priority"),
	RESOLUTION("resolution"),
	HOURS_WORKED("work_time");

	private final String fieldName;

	/**
	 * Used by the {@link BugzillaStandardField} constants to construct "new instances."
	 * 
	 * @param fieldName
	 *            the name of the {@link BugzillaStandardField} (as listed in the <code>Bug.fields</code>
	 *            XML-RPC result)
	 */
	private BugzillaStandardField(String fieldName)
	{
		this.fieldName = fieldName;
	}

	/**
	 * Returns the name of the {@link BugzillaStandardField} (as listed in the <code>Bug.fields</code> XML-RPC
	 * result).
	 * 
	 * @return the name of the {@link BugzillaStandardField} (as listed in the <code>Bug.fields</code> XML-RPC
	 *         result)
	 */
	public String getFieldName()
	{
		return fieldName;
	}

	/**
	 * Returns the {@link BugzillaStandardField} with the specified {@link #getFieldName()}, or
	 * <code>null</code> if no matching {@link BugzillaStandardField} can be found.
	 * 
	 * @param fieldName
	 *            the {@link #getFieldName()} value to match
	 * @return the {@link BugzillaStandardField} with the specified {@link #getFieldName()}, or
	 *         <code>null</code> if no matching {@link BugzillaStandardField} can be found
	 */
	public static BugzillaStandardField getField(String fieldName)
	{
		for (BugzillaStandardField field : BugzillaStandardField.values())
			if (field.fieldName.equals(fieldName))
				return field;

		return null;
	}
}
